﻿<%@page import="com.pb.news.entity.News" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="com.pb.news.util.Page" %>
<%@include file="../common/common.jsp" %><%--静态包含，相当于复制，先包含进来，再处理--%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<script type="text/javascript">

    function addNews() {
        window.location = "newsDetailCreateSimple.jsp";
    }

</script>

<div class="main-content-right">
    <!--即时新闻-->
    <div class="main-text-box">
        <div class="main-text-box-tbg">
            <div class="main-text-box-bbg">
                <form name="searchForm" id="searchForm" action="newsDetailList.jsp" method="post">
                    <div>
                        新闻分类：
                        <select name="categoryId">
                            <option value="0">全部</option>

                            <option value='1'>国内</option>

                            <option value='2'>国际</option>

                            <option value='3'>娱乐</option>

                            <option value='4'>军事</option>

                            <option value='5'>财经</option>

                            <option value='6'>天气</option>

                        </select>
                        新闻标题<input type="text" name="title" id="title" value=''/>
                        <button type="submit" class="page-btn">GO</button>
                        <button type="button" onclick="addNews();" class="page-btn">增加</button>
                        <input type="hidden" name="pageIndex" value="1"/>
                        <%--<input type="hidden" name="pageSize" value="10"/>--%>
                        <%--<input type="hidden" name="totalPageCount" value="2"/>--%>
                    </div>
                </form>
                <table cellpadding="1" cellspacing="1" class="admin-list">
                    <thead>
                    <tr class="admin-list-head">
                        <th>新闻标题</th>
                        <th>作者</th>
                        <th>时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <%
                        /* 获取当前页码 */
                        String currentPage = request.getParameter("pageIndex");
                        if (currentPage == null) {
                            currentPage = "1";
                        }
                        int pageIndex = Integer.parseInt(currentPage);

                        /* 获取新闻纪录 */
                        int totalCount = newsService.getTotalCount();

                        /* 每页显示纪录数 */
                        int pageSize = 2;

                        /* 获取总页数 */
                        Page pages = new Page();
                        pages.setCurrPageNo(pageIndex);
                        pages.setPageSize(pageSize);
                        pages.setRecordCount(totalCount);
                        int totalPage = pages.getTotalPageCount();


                        /* 控制首页和末页 */
                        if (pageIndex < 1) {
                            pageIndex = 1;
                        } else if (pageIndex > totalCount) {
                            pageIndex = totalCount;
                        }

                        /* 每页显示新闻列表 */
                        List<News> newsList = newsService.getPageNewsList(pageIndex, pageSize);
                       /* int i = 0;
                        for (News news : newsList) {
                            request.setAttribute("news", news);
                            i++;*/
                        request.setAttribute("list", newsList);
                    %>
                    <tbody>
                    <c:forEach var="news" items="${list}" varStatus="status">
                        <tr
                                <c:if test="${status.count%2==0}"><%--<%if(i%2!=0){%>--%>class="admin-list-td-h2"<%--<%} %>--%></c:if>>
                            <td>
                                <a href='newsDetailView.jsp?id=${news.id}'><%--<%=news.getTitle() %>--%><%--${news.title}--%>
                                    <c:out value="${news.title}" escapeXml="true"/><%--escapeXml true 的时候会对XML标签进行转译，false的时候不会转译--%>
                                </a></td>
                            <td><%--<%=news.getAuthor()%>--%>
                                <c:out value="${news.author}" default="无"/>
                            </td>

                            <td><%--<%=news.getCreateDate() %>--%><%--${news.createDate}--%> <fmt:formatDate
                                    value="${news.createDate}" pattern="yyyy-MM-dd"/>
                            </td>
                            <td>
                                <a href='
                                    <c:url value="newsDetailView.jsp"><c:param name="id" value="${news.id}"/></c:url>
                                '>修改</a>
                                <a href="javascript:if(confirm('确认是否删除此新闻？')) location='adminNewsDel.jsp?id=2'">删除</a>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                    <%--<%
                        }
                    %>--%>
                </table>
                <c:import url="rollPage.jsp">
                    <c:param name="totalCount" value="<%=Integer.toString(totalCount)%>"/>
                    <c:param name="pageIndex" value="<%=Integer.toString(pageIndex)%>"/>
                    <c:param name="totalPage" value="<%=Integer.toString(totalPage)%>"/>
                </c:import>
            </div>
        </div>
    </div>
</div>
</div>